﻿using System;
using System.Windows;
using GalaSoft.MvvmLight.Threading;
using LiSAClient.WpfClient.ViewModel.Frame.Windows;

namespace LiSAClient.WpfClient.View.Frame.Windows
{
    /// <summary>
    /// Interaction logic for LoadingWindow.xaml
    /// </summary>
    public partial class LoadingWindow : Window
    {
        private DetachedWindowViewModel ViewModel
        {
            get
            {
                return this.DataContext as DetachedWindowViewModel;
            }
        }

        public LoadingWindow()
        {
            InitializeComponent();
            this.Loaded += (s, e) => { this.DataContext.ToString(); };
            this.Loaded += (s, e) => { this.ViewModel.ClosingRequest += this.ViewModelOnClosingRequest; };
        }

        private void ViewModelOnClosingRequest(object sender, EventArgs eventArgs)
        {
            DispatcherHelper.CheckBeginInvokeOnUI(this.Close);
        }

        protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
        {
            this.ViewModel.ClosingRequest -= this.ViewModelOnClosingRequest;
            this.ViewModel.SendClosingRequest();
            base.OnClosing(e);
        }
    }
}